<template>
  <div
    class="head"
    v-if="oItem"
    :class="oItem.active"
    @click="chooseThisControl"
  >
    <img :src="headBlack" alt class="headIcon" />
    <img :src="headBlackR" alt class="headRIcon" />
    <p :style="{ color: oItem.main.pageTopFontColor||'transparent' }">
      {{ oItem.main.pageTitle || "这里是页面标题" }}
    </p>
    <span
      class="back"
      v-if="oItem.main.backButton == 2"
      :style="{ color: oItem.main.pageTopFontColor||'transparent' }"
      ><i class="icon icon-back"></i>返回</span
    >
  </div>
</template>

<script>
import Bus from "@/utils/bus";
import { mapState } from "vuex";
import headBlack from "../../../../assets/images/decorate/head_black.png";
import headBlackR from "../../../../assets/images/decorate/head_black_r.png";
import headWhite from "../../../../assets/images/decorate/head_white.png";
import headWhiteR from "../../../../assets/images/decorate/head_white_r.png";
export default {
  name: "mainPageTop",
  data() {
    return {
      headBlack,
      headBlackR,
      headWhite,
      headWhiteR,
      oItem: null,
    };
  },
  props: ["ename", "id"],
  components: {},
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.init();
    });
    const emitName = this.ename + this.id;
    Bus.$off(emitName);
    Bus.$on(emitName, (control) => {
      //console.log("PageTop被通知更新");
      this.oItem = JSON.parse(control);
    });
  },
  methods: {
    init() {
      this.oItem = null;
      this.oItem = JSON.parse(JSON.stringify(this.decorate.controls[0]));
    },
    //点击 选中 当前组件，同时当前组件数据同步到右侧配置页
    chooseThisControl() {
      this.oItem.active = "active";
      let controls = this.decorate.controls;
      controls.forEach((item) => {
        item.active = "";
      });
      controls[0].active = "active";
      this.$store.dispatch("controls", JSON.parse(JSON.stringify(controls)));
      Bus.$emit("updateMain");
      Bus.$emit(`updateRight`, { index: 0 });
    },
  },
  computed: mapState(["decorate"]),
  watch: {},
};
</script>

<style scoped lang="scss">
.head {
  width: 100%;
  height: 64px;
  background-color: #fff;
  position: relative;
  cursor: pointer;
  outline: #0079fe;
  &.active {
    outline: 1px solid #0079fe;
    margin-bottom: 1px;
  }
  .headIcon {
    width: 100%;
    height: auto;
    display: block;
  }
  .headRIcon {
    position: absolute;
    right: 7px;
    z-index: 2;
    width: 87px;
    height: 32px;
    bottom: 6px;
  }
  p {
    font-weight: 600;
    font-size: 16px;
    text-align: center;
    display: block;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 200px;
    margin: 0 auto;
    color: #212121;
    line-height: 45px;
  }
  .back {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 2;
    height: 45px;
    width: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    i {
      font-size: 14px;
      position: relative;
      top: 1px;
    }
  }
}
</style>
